import 'package:flutter/material.dart';
import 'dart:async';

enum Option{
  A,B
}
class AlertDialogDemo extends StatefulWidget {
  @override
  _AlertDialogDemoState createState() => _AlertDialogDemoState();
}
class _AlertDialogDemoState extends State<AlertDialogDemo> {
   String _choice = 'Nothing';
  Future _openAlert() async{
   final optionChoice =  await showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context){
          return AlertDialog(
              title: Text('AlertDialog'),
              content: Text('Are you sure about this?'),
              actions: <Widget>[
                FlatButton(onPressed: (){
                  Navigator.pop(context,Option.A);
                },
                child: Text('OK')
                ),
                FlatButton(onPressed: (){
                  Navigator.pop(context,Option.B);
                },
                child: Text('Cancel')
                )
              ],

          );
      },
    );
    switch (optionChoice) {
      case Option.A:
         setState(() {
           _choice = 'OK';
         });        
        break;
      case Option.B:
         setState(() {
           _choice = 'Cancel';
         });        
        break;
      default:
    }

  }




  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title:Text('AlertDialogDemo'),
          elevation: 0.0,
        ),
         body: Container(
         padding: EdgeInsets.all(100),
         child: Column(
         mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[ 
          Text('your choice is $_choice'),
           RaisedButton(
             onPressed:_openAlert,
             child: Text('Open the alert'),
             )
          ],
         ),
        ),
    );
  }
}